package org.fujene.communicate.hash;

/**
 * It generates hash.
 * 
 * @author fujisaka_yusuke
 */
@Deprecated
public final class ContentHash{
	public static long getTermHash(String str){
		return Long.rotateLeft(str.hashCode() * 0x123456789ABCDEF1L ^ 0x5555555555555555L, 35);
	}

	public static long getContentHash(long docID){
		return Long.rotateLeft(docID * 0x123456789ABCDEF1L ^ 0xAAAAAAAAAAAAAAAAL, 42);
	}

	public static boolean compareRange(long current, long from, long to){
		// compare FROM and TO
		boolean againstZero = false;
		if(from >= 0 && to >= 0 || from < 0 && to < 0) {
			if(to < from) againstZero = true;
		}else if(from < 0 && to >= 0) againstZero = true;
		
		if(againstZero) {
			if((from >= 0 && to >= 0) || (from < 0 && to < 0)) {
				if(current >= from || current <= to) return true;
				else return false;
			}else{
				if(current >= from && current <= to) return true;
				else return false;
			}
		}else{
			if((from >= 0 && to >= 0) || (from < 0 && to < 0)) {
				if(current >= from && current <= to) return true;
				else return false;
			}else{
				if(current >= from || current <= to) return true;
				else return false;
			}
		}
	}
}
